<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>input</title>
</head>
<body>
    <form name="form1" method="post" action="">
        <table width="300" border="1" cellpadding="0" cellspacing="0" BGCOLOR="#ff7f50" >
            <tr>
                <td width="100" HEIGHT="30" bgcolor="aqua">用户登录</td>
            </tr>
            <tr>
                <td  height="30">用户名:</td>
                <td width="162"><input name="user" type="text" id="user1"></td>
            </tr>
            <tr>
                <td>密&nbsp;&nbsp;码</td>
                <td><input name="pwd" type="text" id="pwd1"></td>
            </tr>
            <tr>
                <td>
                    <input name="Button" type="button" value="登录" onclick="check()">
                    <input name="Submit2" type="reset" value="重置">
                </td>
            </tr>
        </table>
    </form>
</body>
<!--<script type="text/javascript"> -->  // 这种写法是生效的   别忘了  有 text/
<script language="JavaScript">
    function check() {
        // alert("ss");
        var name = form1.user.value;  // 要跟name相对应
        // alert(name);
        var pwd = form1.pwd.value;
        // alert(pwd);
        if(name == "" || name == null) {
            alert('请输入用户名字:');
            form1.user.focus();   // 用户名字文本框获取焦点
            return;
        } else if(pwd == "" || pwd == null) {
            alert("请输入密码:");
            form1.pwd.focus();    // m密码文本框获取焦点
            return;
        }
    }
</script>
</html>